
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System;
using My.Resources;
using TeacherLeftHand.DocEditor;
using TeacherLeftHand.Properties;
using Image = System.Windows.Controls.Image;

public class DocumentTab : TabItem
{
   
    private RoutedEventHandler CloseEvent;
    #region Publics

    public string DocName = null;
    public string FileFormat = "Rich Text Document";
   
    public TabHeader HeaderContent = new TabHeader();
    public DocumentEditor Editor;
    public ScrollViewer ScrllVwer = new ScrollViewer();
    public Label Title = new Label();
    public int MyIndex;
    public bool IsBlank;
   
    public event RoutedEventHandler Close
    {
        add
        {
            CloseEvent = (RoutedEventHandler)System.Delegate.Combine(CloseEvent, value);
        }
        remove
        {
            CloseEvent = (RoutedEventHandler)System.Delegate.Remove(CloseEvent, value);
        }
    }
    #endregion

    #region FileBox

    public DocumentTab()
    {
        //this.LostFocus += new RoutedEventHandler(DocumentTab_LostFocus);
        //this.GotFocus += new RoutedEventHandler(DocumentTab_GotFocus);
    }

    //void DocumentTab_GotFocus(object sender, RoutedEventArgs e)
    //{
    //    HeaderContent.IsEnabled = true;
    //}

    //void DocumentTab_LostFocus(object sender, RoutedEventArgs e)
    //{
    //    HeaderContent.IsEnabled = false;
    //}
    public DocumentTab(string name,bool isBlank):base()
    {
        BorderThickness = new Thickness(0, 0, 0, 0);        
        DocName = name;
        HeaderContent.TabTitle.Content = name;
        HeaderContent.TabTitle.ToolTip = name;
        this.Header = HeaderContent;
        this.Height = 24;
        IsBlank = isBlank;
        ScrllVwer.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
        ScrllVwer.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
        Editor = new DocumentEditor(isBlank);
        Editor.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
        Editor.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
        Content = Editor;

    }


    #endregion

    #region Header

    public void SetFileType(string fileType)
    {
        HeaderContent.FileTypeImage.ToolTip = fileType;
        FileFormat = fileType;
    }

    public void SetDocumentTitle(string title)
    {
        HeaderContent.TabTitle.Content = title;
        DocName = title;
    }


    public void ShowCloseButton()
    {
        if (Settings.Default.Options_Tabs_CloseButtonMode == 0)
        {
            HeaderContent.CloseButton.Visibility = System.Windows.Visibility.Visible;
        }
        else
        {
            if (this.IsSelected)
            {
                HeaderContent.SetMenu(true);
                HeaderContent.CloseButton.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                HeaderContent.SetMenu(false);
                HeaderContent.CloseButton.Visibility = System.Windows.Visibility.Hidden;
            }
        }
    }
    #endregion


}

